package com.aishua.andpaydemo.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;

import com.aishua.andpaydemo.R;


/**
 * Created by aishua on 2018/5/15.
 */

public class HomeHotAdapter extends RecyclerView.Adapter<HomeHotAdapter.MyDeviceViewHoler> {

    private static final String TAG = "HomeHotAdapter-";
    private Context mContext;
    private String[] hotname;
    private Drawable[] hotbg;

    public HomeHotAdapter(Context mContext, String[] hotname, Drawable[] hotbg) {

        this.mContext = mContext;
        this.hotname = hotname;
        this.hotbg = hotbg;

    }

    @Override
    public MyDeviceViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(mContext, R.layout.item_home_hot, null);
        MyDeviceViewHoler holder = new MyDeviceViewHoler(view);
        return holder;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void onBindViewHolder(MyDeviceViewHoler holder, final int position) {

        holder.displayView(position);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                onRecycleViewClickListener.onRecycleViewClick(position);
            }
        });

    }

    @Override
    public int getItemCount() {

        return hotname.length;
    }


    public class MyDeviceViewHoler extends RecyclerView.ViewHolder {

        private RadioButton rb_home_hot;

        public MyDeviceViewHoler(View itemView) {

            super(itemView);
            rb_home_hot = itemView.findViewById(R.id.rb_home_hot);

        }

        @RequiresApi(api = Build.VERSION_CODES.M)
        public void displayView(int position) {

            rb_home_hot.setTextColor(mContext.getColor(R.color.maincolor));
            rb_home_hot.setText(hotname[position]);
            rb_home_hot.setCompoundDrawablesWithIntrinsicBounds(null, hotbg[position], null, null);

        }

    }

    public void setonRecycleViewClickListener(onRecycleViewClickListener onRccycleViewLongClickListener) {
        this.onRecycleViewClickListener = onRccycleViewLongClickListener;
    }

    private onRecycleViewClickListener onRecycleViewClickListener;

    public interface onRecycleViewClickListener {

        public void onRecycleViewClick(int position);

    }
}
